﻿/*----------------------------------------------------------------
// Copyright (C) 2012
// 版权所有
//
// 文件名：OrderOnline_User.cs
// 文件功能描述：
//
//
// 创建标识：Libing 2012-05-08 18:34:52 星期二
//
// 修改标识：
// 修改描述：
//----------------------------------------------------------------*/

using System;
using System.Collections.Generic;
using System.Text;

using System.Data;
using System.Data.SqlClient;

using WMS.DBUtility;

namespace WMS.SQLServerDAL
{
    public class OrderOnline_User : WMS.IDAL.IOrderOnline_User
    {
        #region 基本方法

        /// <summary>
        /// 添加实体
        /// </summary>
        /// <param name="orderOnlineUser">类型为 WMS.Model.OrderOnline_User 的实体</param>
        /// <returns></returns>
        public bool Insert(WMS.Model.OrderOnline_User orderOnlineUser)
        {
            SqlParameter[] parameters = {
				new SqlParameter("@ID", SqlDbType.VarChar, 36),
				new SqlParameter("@LoginID", SqlDbType.VarChar, 36),
				new SqlParameter("@UserName", SqlDbType.VarChar, 20),
				new SqlParameter("@RealName", SqlDbType.NVarChar, 20),
				new SqlParameter("@Sex", SqlDbType.VarChar, 2),
				new SqlParameter("@Tel", SqlDbType.VarChar, 20),
				new SqlParameter("@Address", SqlDbType.NVarChar, 500),
				new SqlParameter("@RoleID", SqlDbType.VarChar, 36),
				new SqlParameter("@Birthday", SqlDbType.VarChar, 20),
				new SqlParameter("@ZipCode", SqlDbType.VarChar, 10),
				new SqlParameter("@Email", SqlDbType.VarChar, 50),
				new SqlParameter("@MobilePhone", SqlDbType.VarChar, 50),
				new SqlParameter("@ProvinceID", SqlDbType.Char, 6),
				new SqlParameter("@CityID", SqlDbType.Char, 6),
				new SqlParameter("@CountyID", SqlDbType.Char, 6),
				new SqlParameter("@RegisterTime", SqlDbType.DateTime, 8),
				new SqlParameter("@UserType", SqlDbType.Int, 4),
				new SqlParameter("@IDCard", SqlDbType.VarChar, 50),
				new SqlParameter("@IDCardAddress", SqlDbType.NVarChar, 500),
				new SqlParameter("@NumberID", SqlDbType.VarChar, 20),
				new SqlParameter("@CII", SqlDbType.VarChar, 50),
                new SqlParameter("@CIIDES", SqlDbType.VarChar, 100),
				new SqlParameter("@PCII", SqlDbType.VarChar, 50),
                new SqlParameter("@WHSWHS", SqlDbType.VarChar, 50),
                new SqlParameter("@WHSLOC", SqlDbType.VarChar, 50)
			};
            parameters[0].Value = orderOnlineUser.Id;
            parameters[1].Value = orderOnlineUser.LoginID;
            parameters[2].Value = orderOnlineUser.UserName;
            parameters[3].Value = orderOnlineUser.RealName;
            parameters[4].Value = orderOnlineUser.Sex;
            parameters[5].Value = orderOnlineUser.Tel;
            parameters[6].Value = orderOnlineUser.Address;
            parameters[7].Value = orderOnlineUser.RoleID;
            parameters[8].Value = orderOnlineUser.Birthday;
            parameters[9].Value = orderOnlineUser.ZipCode;
            parameters[10].Value = orderOnlineUser.Email;
            parameters[11].Value = orderOnlineUser.MobilePhone;
            parameters[12].Value = orderOnlineUser.ProvinceID;
            parameters[13].Value = orderOnlineUser.CityID;
            parameters[14].Value = orderOnlineUser.CountyID;
            parameters[15].Value = orderOnlineUser.RegisterTime;
            parameters[16].Value = orderOnlineUser.UserType;
            parameters[17].Value = orderOnlineUser.IDCard;
            parameters[18].Value = orderOnlineUser.IDCardAddress;
            parameters[19].Value = orderOnlineUser.NumberID;
            parameters[20].Value = string.IsNullOrEmpty(orderOnlineUser.CII) ? "" : orderOnlineUser.CII;  
            parameters[21].Value = string.IsNullOrEmpty(orderOnlineUser.CIIDES) ? "" : orderOnlineUser.CIIDES;
            parameters[22].Value = string.IsNullOrEmpty(orderOnlineUser.PCII) ? "" : orderOnlineUser.PCII; 
            parameters[23].Value = string.IsNullOrEmpty(orderOnlineUser.WHSWHS) ? "" : orderOnlineUser.WHSWHS; 
            parameters[24].Value = string.IsNullOrEmpty(orderOnlineUser.WHSLOC) ? "A" : orderOnlineUser.WHSLOC; 

            try
            {
                int result = DbHelperSQL.ExecuteStoredProcNonQuery("[OrderOnline_User_Insert]", parameters);

                return result > 0;
            }
            catch (SqlException ex)
            {
                throw new Exception(ex.Message, ex);
            }
        }

        /// <summary>
        /// 修改实体
        /// </summary>
        /// <param name="orderOnlineUser">类型为 WMS.Model.OrderOnline_User 的实体</param>
        /// <returns></returns>
        public bool Update(WMS.Model.OrderOnline_User orderOnlineUser)
        {
            SqlParameter[] parameters = {
				new SqlParameter("@ID", SqlDbType.VarChar, 36),
				new SqlParameter("@LoginID", SqlDbType.VarChar, 36),
				new SqlParameter("@UserName", SqlDbType.VarChar, 20),
				new SqlParameter("@RealName", SqlDbType.NVarChar, 20),
				new SqlParameter("@Sex", SqlDbType.VarChar, 2),
				new SqlParameter("@Tel", SqlDbType.VarChar, 20),
				new SqlParameter("@Address", SqlDbType.NVarChar, 500),
				new SqlParameter("@RoleID", SqlDbType.VarChar, 36),
				new SqlParameter("@Birthday", SqlDbType.VarChar, 20),
				new SqlParameter("@ZipCode", SqlDbType.VarChar, 10),
				new SqlParameter("@Email", SqlDbType.VarChar, 50),
				new SqlParameter("@MobilePhone", SqlDbType.VarChar, 50),
				new SqlParameter("@ProvinceID", SqlDbType.Char, 6),
				new SqlParameter("@CityID", SqlDbType.Char, 6),
				new SqlParameter("@CountyID", SqlDbType.Char, 6),
				new SqlParameter("@RegisterTime", SqlDbType.DateTime, 8),
				new SqlParameter("@UserType", SqlDbType.Int, 4),
				new SqlParameter("@IDCard", SqlDbType.VarChar, 50),
				new SqlParameter("@IDCardAddress", SqlDbType.NVarChar, 500),
				new SqlParameter("@NumberID", SqlDbType.VarChar, 20),
				new SqlParameter("@CII", SqlDbType.VarChar, 50),
                new SqlParameter("@CIIDES", SqlDbType.VarChar, 100),
				new SqlParameter("@PCII", SqlDbType.VarChar, 50),
                new SqlParameter("@WHSWHS", SqlDbType.VarChar, 50),
                new SqlParameter("@WHSLOC", SqlDbType.VarChar, 50)
			};
            parameters[0].Value = orderOnlineUser.Id;
            parameters[1].Value = orderOnlineUser.LoginID;
            parameters[2].Value = orderOnlineUser.UserName;
            parameters[3].Value = orderOnlineUser.RealName;
            parameters[4].Value = orderOnlineUser.Sex;
            parameters[5].Value = orderOnlineUser.Tel;
            parameters[6].Value = orderOnlineUser.Address;
            parameters[7].Value = orderOnlineUser.RoleID;
            parameters[8].Value = orderOnlineUser.Birthday;
            parameters[9].Value = orderOnlineUser.ZipCode;
            parameters[10].Value = orderOnlineUser.Email;
            parameters[11].Value = orderOnlineUser.MobilePhone;
            parameters[12].Value = orderOnlineUser.ProvinceID;
            parameters[13].Value = orderOnlineUser.CityID;
            parameters[14].Value = orderOnlineUser.CountyID;
            parameters[15].Value = orderOnlineUser.RegisterTime;
            parameters[16].Value = orderOnlineUser.UserType;
            parameters[17].Value = orderOnlineUser.IDCard;
            parameters[18].Value = orderOnlineUser.IDCardAddress;
            parameters[19].Value = orderOnlineUser.NumberID;
            parameters[20].Value = string.IsNullOrEmpty(orderOnlineUser.CII) ? "" : orderOnlineUser.CII;
            parameters[21].Value = string.IsNullOrEmpty(orderOnlineUser.CIIDES) ? "" : orderOnlineUser.CIIDES;
            parameters[22].Value = string.IsNullOrEmpty(orderOnlineUser.PCII) ? "" : orderOnlineUser.PCII;
            parameters[23].Value = string.IsNullOrEmpty(orderOnlineUser.WHSWHS) ? "" : orderOnlineUser.WHSWHS;
            parameters[24].Value = string.IsNullOrEmpty(orderOnlineUser.WHSLOC) ? "A" : orderOnlineUser.WHSLOC;

            try
            {
                return DbHelperSQL.ExecuteStoredProcNonQuery("[OrderOnline_User_Update]", parameters) > 0;
            }
            catch (SqlException ex)
            {
                throw new Exception(ex.Message, ex);
            }
        }

        /// <summary>
        /// 最小修改实体
        /// </summary>
        /// <param name="model">类型为WMS.Model.OrderOnline_User的实体</param>
        /// <returns></returns>
        public bool UpdateMinimal(WMS.Model.OrderOnline_User orderOnlineUser)
        {
            SqlCommand cmd = new SqlCommand("[OrderOnline_User_UpdateMinimal]");

            if (!String.IsNullOrEmpty(orderOnlineUser.Id))
            {
                cmd.Parameters.Add(new SqlParameter("@ID", SqlDbType.VarChar, 36)).Value = orderOnlineUser.Id;
            }

            if (!String.IsNullOrEmpty(orderOnlineUser.LoginID))
            {
                cmd.Parameters.Add(new SqlParameter("@LoginID", SqlDbType.VarChar, 36)).Value = orderOnlineUser.LoginID;
            }

            if (!String.IsNullOrEmpty(orderOnlineUser.UserName))
            {
                cmd.Parameters.Add(new SqlParameter("@UserName", SqlDbType.VarChar, 20)).Value = orderOnlineUser.UserName;
            }

            if (!String.IsNullOrEmpty(orderOnlineUser.RealName))
            {
                cmd.Parameters.Add(new SqlParameter("@RealName", SqlDbType.NVarChar, 20)).Value = orderOnlineUser.RealName;
            }

            if (!String.IsNullOrEmpty(orderOnlineUser.Sex))
            {
                cmd.Parameters.Add(new SqlParameter("@Sex", SqlDbType.VarChar, 2)).Value = orderOnlineUser.Sex;
            }

            if (!String.IsNullOrEmpty(orderOnlineUser.Tel))
            {
                cmd.Parameters.Add(new SqlParameter("@Tel", SqlDbType.VarChar, 20)).Value = orderOnlineUser.Tel;
            }

            if (!String.IsNullOrEmpty(orderOnlineUser.Address))
            {
                cmd.Parameters.Add(new SqlParameter("@Address", SqlDbType.NVarChar, 500)).Value = orderOnlineUser.Address;
            }

            if (!String.IsNullOrEmpty(orderOnlineUser.RoleID))
            {
                cmd.Parameters.Add(new SqlParameter("@RoleID", SqlDbType.VarChar, 36)).Value = orderOnlineUser.RoleID;
            }

            if (!String.IsNullOrEmpty(orderOnlineUser.Birthday))
            {
                cmd.Parameters.Add(new SqlParameter("@Birthday", SqlDbType.VarChar, 20)).Value = orderOnlineUser.Birthday;
            }

            if (!String.IsNullOrEmpty(orderOnlineUser.ZipCode))
            {
                cmd.Parameters.Add(new SqlParameter("@ZipCode", SqlDbType.VarChar, 10)).Value = orderOnlineUser.ZipCode;
            }

            if (!String.IsNullOrEmpty(orderOnlineUser.Email))
            {
                cmd.Parameters.Add(new SqlParameter("@Email", SqlDbType.VarChar, 50)).Value = orderOnlineUser.Email;
            }

            if (!String.IsNullOrEmpty(orderOnlineUser.MobilePhone))
            {
                cmd.Parameters.Add(new SqlParameter("@MobilePhone", SqlDbType.VarChar, 50)).Value = orderOnlineUser.MobilePhone;
            }

            if (!String.IsNullOrEmpty(orderOnlineUser.ProvinceID))
            {
                cmd.Parameters.Add(new SqlParameter("@ProvinceID", SqlDbType.Char, 6)).Value = orderOnlineUser.ProvinceID;
            }

            if (!String.IsNullOrEmpty(orderOnlineUser.CityID))
            {
                cmd.Parameters.Add(new SqlParameter("@CityID", SqlDbType.Char, 6)).Value = orderOnlineUser.CityID;
            }

            if (!String.IsNullOrEmpty(orderOnlineUser.CountyID))
            {
                cmd.Parameters.Add(new SqlParameter("@CountyID", SqlDbType.Char, 6)).Value = orderOnlineUser.CountyID;
            }

            if (orderOnlineUser.RegisterTime != null)
            {
                cmd.Parameters.Add(new SqlParameter("@RegisterTime", SqlDbType.DateTime, 8)).Value = orderOnlineUser.RegisterTime;
            }

            if (orderOnlineUser.UserType != null)
            {
                cmd.Parameters.Add(new SqlParameter("@UserType", SqlDbType.Int, 4)).Value = orderOnlineUser.UserType;
            }

            if (!String.IsNullOrEmpty(orderOnlineUser.IDCard))
            {
                cmd.Parameters.Add(new SqlParameter("@IDCard", SqlDbType.VarChar, 50)).Value = orderOnlineUser.IDCard;
            }

            if (!String.IsNullOrEmpty(orderOnlineUser.IDCardAddress))
            {
                cmd.Parameters.Add(new SqlParameter("@IDCardAddress", SqlDbType.NVarChar, 500)).Value = orderOnlineUser.IDCardAddress;
            }

            if (!String.IsNullOrEmpty(orderOnlineUser.NumberID))
            {
                cmd.Parameters.Add(new SqlParameter("@NumberID", SqlDbType.VarChar, 20)).Value = orderOnlineUser.NumberID;
            }

            if (!String.IsNullOrEmpty(orderOnlineUser.CII))
            {
                cmd.Parameters.Add(new SqlParameter("@CII", SqlDbType.VarChar, 50)).Value = orderOnlineUser.CII;
            }

            if (!String.IsNullOrEmpty(orderOnlineUser.CIIDES))
            {
                cmd.Parameters.Add(new SqlParameter("@CIIDES", SqlDbType.VarChar, 50)).Value = orderOnlineUser.CIIDES;
            }
            if (!String.IsNullOrEmpty(orderOnlineUser.PCII))
            {
                cmd.Parameters.Add(new SqlParameter("@PCII", SqlDbType.VarChar, 50)).Value = orderOnlineUser.PCII;
            }

            if (!String.IsNullOrEmpty(orderOnlineUser.WHSWHS))
            {
                cmd.Parameters.Add(new SqlParameter("@WHSWHS", SqlDbType.VarChar, 50)).Value = orderOnlineUser.WHSWHS;
            }
            if (!String.IsNullOrEmpty(orderOnlineUser.WHSLOC))
            {
                cmd.Parameters.Add(new SqlParameter("@WHSLOC", SqlDbType.VarChar, 50)).Value = orderOnlineUser.WHSLOC;
            }

            try
            {
                return DbHelperSQL.ExecuteStoredProcNonQuery(cmd) > 0;
            }
            catch (SqlException ex)
            {
                throw new Exception(ex.Message, ex);
            }
        }

        /// <summary>
        /// 删除实体(指定条件)
        /// </summary>
        /// <param name="whereClause">WHERE语句</param>
        /// <returns></returns>
        public bool DeleteDynamic(string whereClause)
        {
            SqlParameter[] parameters = {
				new SqlParameter("@WhereClause", SqlDbType.NVarChar,2000)
			};
            parameters[0].Value = whereClause;

            try
            {
                return DbHelperSQL.ExecuteStoredProcNonQuery("[OrderOnline_User_DeleteDynamic]", parameters) > 0;
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message, ex);
            }
        }

        #endregion

        #region	公共方法

        /// <summary>
        /// 获取实体列表(指定数目和查询条件)
        /// </summary>
        /// <param name="topClause">指定实体数</param>
        /// <param name="whereClause">WHERE语句</param>
        /// <returns></returns>
        public List<WMS.Model.OrderOnline_User> Get(int topClause, string whereClause)
        {
            SqlParameter[] parameters = {
				new SqlParameter("@TopClause", SqlDbType.Int,4),
				new SqlParameter("@WhereClause", SqlDbType.NVarChar,2000)
			};
            parameters[0].Value = topClause;
            parameters[1].Value = whereClause;

            try
            {
                List<WMS.Model.OrderOnline_User> orderOnlineUserList = new List<WMS.Model.OrderOnline_User>();

                SqlDataReader dr = DbHelperSQL.ExecuteStoredProcReader("[OrderOnline_User_GetDynamic]", parameters);
                while (dr.Read())
                {
                    WMS.Model.OrderOnline_User orderOnlineUser = new WMS.Model.OrderOnline_User();

                    orderOnlineUser.Id = Convert.ToString(dr["ID"]);
                    orderOnlineUser.LoginID = Convert.ToString(dr["LoginID"]);
                    orderOnlineUser.UserName = Convert.ToString(dr["UserName"]);
                    orderOnlineUser.RealName = Convert.ToString(dr["RealName"]);
                    orderOnlineUser.Sex = Convert.ToString(dr["Sex"]);
                    orderOnlineUser.Tel = Convert.ToString(dr["Tel"]);
                    orderOnlineUser.Address = Convert.ToString(dr["Address"]);
                    orderOnlineUser.RoleID = Convert.ToString(dr["RoleID"]);
                    orderOnlineUser.Birthday = Convert.ToString(dr["Birthday"]);
                    orderOnlineUser.ZipCode = Convert.ToString(dr["ZipCode"]);
                    orderOnlineUser.Email = Convert.ToString(dr["Email"]);
                    orderOnlineUser.MobilePhone = Convert.ToString(dr["MobilePhone"]);
                    orderOnlineUser.ProvinceID = Convert.ToString(dr["ProvinceID"]);
                    orderOnlineUser.CityID = Convert.ToString(dr["CityID"]);
                    orderOnlineUser.CountyID = Convert.ToString(dr["CountyID"]);
                    orderOnlineUser.RegisterTime = Convert.ToDateTime(dr["RegisterTime"]).ToString("yyyy-MM-dd");
                    orderOnlineUser.UserType = Convert.ToInt32(dr["UserType"]);
                    orderOnlineUser.IDCard = Convert.ToString(dr["IDCard"]);
                    orderOnlineUser.IDCardAddress = Convert.ToString(dr["IDCardAddress"]);
                    orderOnlineUser.NumberID = Convert.ToString(dr["NumberID"]);
                    orderOnlineUser.CII = Convert.ToString(dr["CII"]);
                    orderOnlineUser.CIIDES = Convert.ToString(dr["CIIDES"]);
                    orderOnlineUser.PCII = Convert.ToString(dr["PCII"]);
                    orderOnlineUser.WHSWHS = Convert.ToString(dr["WHSWHS"]);
                    orderOnlineUser.WHSLOC = Convert.ToString(dr["WHSLOC"]);
                    orderOnlineUser.ModelState = WMS.Model.Enum.ModelState.None;

                    orderOnlineUserList.Add(orderOnlineUser);
                }

                // Close the dr, which will cause the connection to be closed as well.
                dr.Close();

                return orderOnlineUserList;
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message, ex);
            }
        }

        /// <summary>
        /// 获取实体列表(指定查询条件)
        /// </summary>
        /// <param name="whereClause">WHERE语句</param>
        /// <returns></returns>
        public List<WMS.Model.OrderOnline_User> Get(string whereClause)
        {
            return Get(0, whereClause);
        }

        /// <summary>
        /// 获取分页实体列表
        /// </summary>
        /// <param name="whereClause">WHERE 语句</param>
        /// <param name="orderByClause">ORDER BY 语句</param>
        /// <param name="pageIndex">分页索引</param>
        /// <param name="pageSize">分页大小(每页显示的记录数)</param>
        /// <param name="totalRecords">记录总数</param>
        /// <returns></returns>
        public List<WMS.Model.OrderOnline_User> GetPaged(string whereClause, string orderBy, int pageIndex, int pageSize, out int totalRecords)
        {
            SqlParameter[] parameters = {
				new SqlParameter("@WhereClause", SqlDbType.NVarChar, 2000),
				new SqlParameter("@OrderBy", SqlDbType.NVarChar, 1000),
				new SqlParameter("@PageIndex", SqlDbType.Int, 4),
				new SqlParameter("@PageSize", SqlDbType.Int, 4)
			};
            parameters[0].Value = whereClause;
            parameters[1].Value = orderBy;
            parameters[2].Value = pageIndex;
            parameters[3].Value = pageSize;

            try
            {
                List<WMS.Model.OrderOnline_User> orderOnlineUserList = new List<WMS.Model.OrderOnline_User>();

                SqlDataReader dr = DbHelperSQL.ExecuteStoredProcReader("[OrderOnline_User_GetPaged]", parameters);
                while (dr.Read())
                {
                    WMS.Model.OrderOnline_User orderOnlineUser = new WMS.Model.OrderOnline_User();

                    orderOnlineUser.Id = Convert.ToString(dr["ID"]);
                    orderOnlineUser.LoginID = Convert.ToString(dr["LoginID"]);
                    orderOnlineUser.UserName = Convert.ToString(dr["UserName"]);
                    orderOnlineUser.RealName = Convert.ToString(dr["RealName"]);
                    orderOnlineUser.Sex = Convert.ToString(dr["Sex"]);
                    orderOnlineUser.Tel = Convert.ToString(dr["Tel"]);
                    orderOnlineUser.Address = Convert.ToString(dr["Address"]);
                    orderOnlineUser.RoleID = Convert.ToString(dr["RoleID"]);
                    orderOnlineUser.Birthday = Convert.ToString(dr["Birthday"]);
                    orderOnlineUser.ZipCode = Convert.ToString(dr["ZipCode"]);
                    orderOnlineUser.Email = Convert.ToString(dr["Email"]);
                    orderOnlineUser.MobilePhone = Convert.ToString(dr["MobilePhone"]);
                    orderOnlineUser.ProvinceID = Convert.ToString(dr["ProvinceID"]);
                    orderOnlineUser.CityID = Convert.ToString(dr["CityID"]);
                    orderOnlineUser.CountyID = Convert.ToString(dr["CountyID"]);
                    orderOnlineUser.RegisterTime = Convert.ToDateTime(dr["RegisterTime"]).ToString("yyyy-MM-dd");
                    orderOnlineUser.UserType = Convert.ToInt32(dr["UserType"]);
                    orderOnlineUser.IDCard = Convert.ToString(dr["IDCard"]);
                    orderOnlineUser.IDCardAddress = Convert.ToString(dr["IDCardAddress"]);
                    orderOnlineUser.NumberID = Convert.ToString(dr["NumberID"]);
                    orderOnlineUser.CII = Convert.ToString(dr["CII"]);
                    orderOnlineUser.CIIDES = Convert.ToString(dr["CIIDES"]);
                    orderOnlineUser.PCII = Convert.ToString(dr["PCII"]);
                    orderOnlineUser.WHSWHS = Convert.ToString(dr["WHSWHS"]);
                    orderOnlineUser.WHSLOC = Convert.ToString(dr["WHSLOC"]);
                    orderOnlineUser.ModelState = WMS.Model.Enum.ModelState.None;

                    orderOnlineUserList.Add(orderOnlineUser);
                }

                totalRecords = orderOnlineUserList.Count;

                if (dr.NextResult())
                {
                    if (dr.Read())
                    {
                        totalRecords = Convert.ToInt32(dr[0]);
                    }
                }

                // Close the dr, which will cause the connection to be closed as well.
                dr.Close();

                return orderOnlineUserList;
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message, ex);
            }
        }

        #endregion

        #region 自定义方法

        /// <summary>
        /// 删除实体(根据主键 ID)
        /// </summary>
        /// <param name="id">主键ID</param>
        /// <returns></returns>
        public bool DeleteByID(string id)
        {
            SqlParameter[] parameters = {
				new SqlParameter("@ID", SqlDbType.VarChar,36)
			};
            parameters[0].Value = id;

            try
            {
                return DbHelperSQL.ExecuteStoredProcNonQuery("[OrderOnline_User_DeleteByID]", parameters) > 0;
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message, ex);
            }
        }

        /// <summary>
        /// 获取实体(根据主键 ID)
        /// </summary>
        /// <param name="id">主键ID</param>
        /// <returns></returns>
        public WMS.Model.OrderOnline_User GetByID(string id)
        {
            SqlParameter[] parameters = {
				new SqlParameter("@ID", SqlDbType.VarChar,36)
			};
            parameters[0].Value = id;

            try
            {
                List<WMS.Model.OrderOnline_User> orderOnlineUserList = new List<WMS.Model.OrderOnline_User>();

                SqlDataReader dr = DbHelperSQL.ExecuteStoredProcReader("[OrderOnline_User_GetByID]", parameters);
                while (dr.Read())
                {
                    WMS.Model.OrderOnline_User orderOnlineUser = new WMS.Model.OrderOnline_User();

                    orderOnlineUser.Id = Convert.ToString(dr["ID"]);
                    orderOnlineUser.LoginID = Convert.ToString(dr["LoginID"]);
                    orderOnlineUser.UserName = Convert.ToString(dr["UserName"]);
                    orderOnlineUser.RealName = Convert.ToString(dr["RealName"]);
                    orderOnlineUser.Sex = Convert.ToString(dr["Sex"]);
                    orderOnlineUser.Tel = Convert.ToString(dr["Tel"]);
                    orderOnlineUser.Address = Convert.ToString(dr["Address"]);
                    orderOnlineUser.RoleID = Convert.ToString(dr["RoleID"]);
                    orderOnlineUser.Birthday = Convert.ToString(dr["Birthday"]);
                    orderOnlineUser.ZipCode = Convert.ToString(dr["ZipCode"]);
                    orderOnlineUser.Email = Convert.ToString(dr["Email"]);
                    orderOnlineUser.MobilePhone = Convert.ToString(dr["MobilePhone"]);
                    orderOnlineUser.ProvinceID = Convert.ToString(dr["ProvinceID"]);
                    orderOnlineUser.CityID = Convert.ToString(dr["CityID"]);
                    orderOnlineUser.CountyID = Convert.ToString(dr["CountyID"]);
                    orderOnlineUser.RegisterTime = Convert.ToDateTime(dr["RegisterTime"]).ToString("yyyy-MM-dd");
                    orderOnlineUser.UserType = Convert.ToInt32(dr["UserType"]);
                    orderOnlineUser.IDCard = Convert.ToString(dr["IDCard"]);
                    orderOnlineUser.IDCardAddress = Convert.ToString(dr["IDCardAddress"]);
                    orderOnlineUser.NumberID = Convert.ToString(dr["NumberID"]);
                    orderOnlineUser.CII = Convert.ToString(dr["CII"]);
                    orderOnlineUser.CIIDES = Convert.ToString(dr["CIIDES"]);
                    orderOnlineUser.PCII = Convert.ToString(dr["PCII"]);
                    orderOnlineUser.WHSWHS = Convert.ToString(dr["WHSWHS"]);
                    orderOnlineUser.WHSLOC = Convert.ToString(dr["WHSLOC"]);
                    orderOnlineUser.ModelState = WMS.Model.Enum.ModelState.None;

                    orderOnlineUserList.Add(orderOnlineUser);
                }

                // Close the dr, which will cause the connection to be closed as well.
                dr.Close();

                if (orderOnlineUserList.Count > 0)
                {
                    return orderOnlineUserList[0];
                }
                else
                {
                    return null;
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message, ex);
            }
        }

        /// <summary>
        /// 根据过滤条件获取分页实体列表
        /// </summary>
        /// <param name="userName">用户名</param>
        /// <param name="realName">姓名</param>
        /// <param name="pageIndex">分页索引</param>
        /// <param name="pageSize">分页大小(每页显示的记录数)</param>
        /// <param name="totalRecords">记录总数</param>
        /// <returns></returns>
        public List<WMS.Model.OrderOnline_User> GetFilterPaged(string userName, string realName, string CII, int pageIndex, int pageSize, out int totalRecords)
        {
            StringBuilder whereClause = new StringBuilder();
            whereClause.Append("UserType=5");
            if (!String.IsNullOrEmpty(userName))
            {
                whereClause.AppendFormat(" AND UserName LIKE '%{0}%'", userName);
            }

            if (!String.IsNullOrEmpty(realName))
            {
                whereClause.AppendFormat(" AND RealName LIKE '%{0}%'", realName);
            }

            if (!String.IsNullOrEmpty(CII))
            {
                whereClause.AppendFormat(" AND CII= '{0}'", CII);
            }

            return GetPaged(whereClause.ToString(), "RegisterTime DESC", pageIndex, pageSize, out totalRecords);
        }

        /// <summary>
        /// 检查用户名是否已存在
        /// </summary>
        /// <param name="userName">用户名</param>
        /// <returns></returns>
        public bool Exists(string userName)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.AppendFormat("SELECT COUNT(1) FROM OrderOnline_User WHERE UserName='{0}'", userName);

            return Convert.ToInt32(DbHelperSQL.ExecuteSqlStringScalar(strSql.ToString())) > 0;
        }

        /// <summary>
        /// 根据LoginID获取实体
        /// </summary>
        /// <param name="loginID">登录ID</param>
        /// <returns></returns>
        public WMS.Model.OrderOnline_User GetByLoginID(string loginID)
        {
            List<WMS.Model.OrderOnline_User> orderOnlineUserList = Get(String.Format("LoginID='{0}'", loginID));

            if (orderOnlineUserList.Count > 0)
            {
                return orderOnlineUserList[0];
            }

            return null;
        }

        /// <summary>
        /// 判断用户的AdminNew
        /// </summary>
        /// <param name="loginID">用户ID</param>
        /// <returns></returns>
        public bool CheckDeleteByAdminNew(string loginID)
        {
            bool result = false;

            if (Convert.ToInt32(DbHelperSQL.ExecuteSqlStringScalar(String.Format("SELECT COUNT(1) FROM OrderOnline_User WHERE ID='{0}' AND AdminNew='T'", loginID))) > 0)
            {
                result = true;
            }

            return result;
        }

        /// <summary>
        /// 判断角色是否存在用户
        /// </summary>
        /// <param name="roleID">角色ID</param>
        /// <returns></returns>
        public bool CheckExistsByRoleID(string roleID)
        {
            return Convert.ToInt32(DbHelperSQL.ExecuteSqlStringScalar(String.Format("SELECT COUNT(1) FROM OrderOnline_User WHERE RoleID='{0}'", roleID))) > 0;
        }

        #endregion
    }
}
